var LocalStorageServiciosAdapter = function () {

    var estado_visible=1;

    this.initialize = function() {
        var deferred = $.Deferred();

        //Solo Guardaremos las categorias la primera vez
        //if(window.localStorage.getItem('ejecutado')==null){
            // First RUN
            //window.localStorage.setItem('ejecutado','1'); 

            // Store sample data in Local Storage
            window.localStorage.setItem("servicios_estaticos", JSON.stringify(
				[
					{"id":"-1","id_hotel":"1","precio":"","img_thumb":"./img/greek1.png","id_servicio":"1","id_idioma":"1","nombre_menu":"Estatico1","nombre":"","descripcion":"","horario":""},
					{"id":"-2","id_hotel":"1","precio":"","img_thumb":"./img/greek1.png","id_servicio":"6","id_idioma":"1","nombre_menu":"Estatico2","nombre":"","descripcion":"","horario":""}
				]
            ));
        //}

        deferred.resolve();
        return deferred.promise();
    }


    this.getServiciosEstaticos = function () {
        var deferred = $.Deferred(),
        servicios = JSON.parse(window.localStorage.getItem("servicios_estaticos"));
        deferred.resolve(servicios);
        return deferred.promise();
    }

    this.findById = function (id) {

        var deferred = $.Deferred(),
            categorias = JSON.parse(window.localStorage.getItem("categorias")),
            categoria = null,
            l = categorias.length;

        for (var i = 0; i < l; i++) {
            if (categorias[i].id_categoria === id) {
                categoria = categorias[i];
                break;
            }
        }

        deferred.resolve(categoria);
        return deferred.promise();
    }

    this.findCategoriasAlertas = function () {
        var deferred = $.Deferred(),
            categorias = JSON.parse(window.localStorage.getItem("categorias")),
            results = categorias.filter(function (element) {
                return element.alertas_estado==estado_visible;
            });
        deferred.resolve(results);
        return deferred.promise();
    }

    this.findCategoriasNoticias = function () {
        var deferred = $.Deferred(),
            categorias = JSON.parse(window.localStorage.getItem("categorias")),
            results = categorias.filter(function (element) {
                return element.noticias_estado==estado_visible;
            });
        deferred.resolve(results);
        return deferred.promise();
    }
}